package com.lovo.ssc.service.impl;

import com.lovo.dto.FrozenDto;
import com.lovo.ssc.entity.Customer;
import com.lovo.ssc.service.ICustomerService;
import com.lovo.util.MQUtil;
import com.rabbitmq.client.Channel;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.amqp.support.AmqpHeaders;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.messaging.handler.annotation.Header;
import org.springframework.stereotype.Service;

@Service
public class CustomerMQService {

    @Autowired
    ICustomerService customerService;
    @RabbitListener(queues = MQUtil.houQueue)
    public void customer(Channel channel, @Header(AmqpHeaders.DELIVERY_TAG) long tag, FrozenDto dto)throws Exception{
        if (dto!=null){
            Customer customer = new Customer();
            customer.setRealname(dto.getRealName());
            customer.setUsername(dto.getUserName());
            if (dto.getUserSex().equals("男")){
                customer.setSex("0");
            }else {
                customer.setSex("1");
            }
            customer.setPhone(dto.getUserPhone());
            customer.setImage(dto.getUserQualification());
            customer.setSfzimg(dto.getUserCard());
            customer.setCompanyname(dto.getUserPompany());
            customer.setGrade(dto.getGrade());
            customer.setState("正常");
            customer.setCode("Y"+System.currentTimeMillis());
            customerService.save(customer);
        }
        channel.basicAck(tag,false); //false不进行批量确认
    }
}
